package prac.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;

import prac.dao.PracDAO;
import prac.forms.PracForm;

public class PracAction extends Action{
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
			throws Exception {

			ActionErrors errors = new ActionErrors();
			ActionForward forward = new ActionForward(); 
			PracForm pForm = (PracForm) form;
			String result = "";
			PracDAO pDAO = new PracDAO();
			
			try{ 
				
				if("insert".equals(pForm.getFlag())){
					pDAO.insert_personal(pForm);
				}
				
				result = pDAO.draw_personal();
				
			} catch (Exception e) {
				e.printStackTrace();		
			}finally{
				request.setAttribute("json", result);	
				forward = mapping.findForward("success");
			}
					
			return (forward);
		}
	}

